home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-16 | 14.1 KB | 1,074 lines |
- testmode = 1
-
- include "src:shadowlord.i"
-
- ; V1.01
- ; Added bigger understanding of PC box characters.
- ; Now also understands one-wide box chars, and thick corner changed to #,
- ; single corner to +.
-
- ; V1.02
- ; Added bad mode error, and error on no space between mode and the rest.
-
- ; V1.10
- ; Cut endspace.
- ; Text output.
-
- ; V1.13
- ; Percentage & size change
- ; extra lf
- ; extra cr removal in topc mode
-
- ; V1.16
- ; Faster translate routines 25% speedup in frompc
- ; 6 more in frompc
- ; New helptext.
-
- ; V1.18 11-feb
- ; Upper and lower case modes.
-
- ; V1.21 15-feb
- ; tabs to spaces
- ; 3 new pc box chars
- ; bug fixed that confused port if the end of the commandline had spaces.
-
- * 15-Feb-93
- * 15 days of hard coding
-
- ; during the program
- ; a0=source
- ; a1=dest
- ; a2=spacebuf
-
- ; d0=current char
- ; d1=load counter
- ; d2=savebyte counter
-
-
- if testmode=1
- lea test_comline,a0
- move.l #test_len,d0
- endc
-
- progstart:
- clr.b -1(a0,d0.l)
- move.l a0,commandstart
- move.w d0,commandlen
- add.l d0,a0
- subq.l #1,a0
- move.l a0,commandend
-
- lea dosname,a1
- moveq #0,d0
- move.l execbase,a6
- jsr openlibrary(a6)
- move.l d0,dosbase
-
- move.l dosbase,a6
- jsr output(a6)
- move.l d0,outstruct
-
- if testmode=1
- bne err_testmode
- endc
-
- move.l #text_cursoroff,d2
- moveq #5,d3
- bsr printtext
-
- move.l commandstart,a0
- tst.b (a0) ; if blank commandline, instructions
- beq helptext
- cmp.b #"?",(a0)
- beq helptext
-
- parsestart:
- cmp.b #"-",(a0)
- beq checkoption
-
- parse:
- cmp.b #" ",1(a0) ; at least one space after option
- bne err_nocomlinespace
- cmp.b #"p",(a0)
- beq frompcmode
- cmp.b #"P",(a0)
- beq topcmode
- cmp.b #"s",(a0)
- beq fromsf7mode
- cmp.b #"S",(a0)
- beq tosf7mode
- cmp.b #"u",(a0)
- beq toupcasemode
- cmp.b #"l",(a0)
- beq tolowcasemode
- bra err_badmode
-
- checkoption:
- cmp.b #"n",1(a0)
- beq opt_nocutspace
- cmp.b #"?",1(a0)
- beq credits
- cmp.b #"t",1(a0)
- beq opt_tabconv
- bra err_badcomline
-
- opt_nocutspace:
- clr.b mode_cutspace
- addq.l #2,a0
- cmp.b #" ",(a0)
- bne err_badcomline
- bsr skipspace
- cmp.l #0,a0
- beq err_badcomline
- bra parsestart
-
- opt_tabconv:
- addq.l #2,a0 ; can be optimized; drop second
- move.b (a0),d0 ; addq.l #n,a0
- ext.w d0
- ext.l d0
- cmp.b #" ",d0
- beq opt_tabconv2
- sub.b #"0",d0
- cmp.b #9,d0
- bhi err_badcomline
- cmp.b #1,d0
- bcs err_badcomline
- move.b d0,tabsize
- addq.l #1,a0
- cmp.b #" ",(a0)
- bne err_badcomline
-
- opt_tabconv1:
- bsr skipspace
- cmp.l #0,a0
- beq err_badcomline
- bra parsestart
-
- opt_tabconv2:
- move.b #8,tabsize
- bra opt_tabconv1
-
- frompcmode:
- move.b #1,mode
- bra nameparse
-
- fromsf7mode:
- move.b #2,mode
- bra nameparse
-
- tosf7mode:
- move.b #-2,mode
- bra nameparse
-
- topcmode:
- move.b #-1,mode
- bra nameparse
-
- toupcasemode:
- move.b #3,mode
- bra nameparse
-
- tolowcasemode:
- move.b #4,mode
- bra nameparse
-
- nameparse:
- addq.l #1,a0
- bsr skipspace
- cmp.l #0,a0
- beq err_badcomline
- move.l a0,sourcenamestart
- bsr findend
- cmp.l #0,a0
- beq err_badcomline
- move.l a0,sourcenameend
- addq.l #1,a0
- sub.l sourcenamestart,a0
- move.l a0,sourcenamelen
-
- move.l sourcenamestart,a0
- move.l #sourcename,a1
- move.l sourcenamelen,d0
- subq.l #1,d0
- cmp.b #'"',(a0)
- beq removequotes
-
- copysourcename:
- move.b (a0)+,(a1)+
- dbf d0,copysourcename
- clr.b (a1)
-
- move.l sourcenameend,a0
- addq.l #1,a0
- cmp.l commandend,a0
- beq nodest
-
- bsr skipspace
- cmp.l #0,a0
- beq nodest
- move.l a0,destnamestart
- bsr findend
- cmp.l #0,a0
- beq err_badcomline
- move.l a0,destnameend
- addq.l #1,a0
- sub.l destnamestart,a0
- move.l a0,destnamelen
- move.l a0,d0
-
- move.l destnamestart,a0
- move.l #destname,a1
- subq.l #1,d0
- cmp.b #'"',(a0)
- beq removequotes1
-
- copydestname:
- move.b (a0)+,(a1)+
- dbf d0,copydestname
- bra openfiles
-
- removequotes:
- addq.l #1,a0
- subq.l #2,d0
- bra copysourcename
-
- removequotes1:
- addq.l #1,a0
- subq.l #2,d0
- bra copydestname
-
- removequotes2:
- addq.l #1,a0
- subq.l #2,d0
- bra copydestname1
-
- nodest:
- move.l #destname,a1
- move.l sourcenamestart,a0
- move.l sourcenamelen,d0
- subq.l #1,d0
- cmp.b #'"',(a0)
- beq removequotes2
-
- copydestname1:
- move.b (a0)+,(a1)+
- dbf d0,copydestname1
-
- cmp.b #-1,mode
- beq pcsuffix
- cmp.b #-2,mode
- beq sf7suffix
-
- amigasuffix:
- lea text_amigasuf,a0
- moveq #4-1,d0
-
- amigasuffix1:
- move.b (a0)+,(a1)+
- dbf d0,amigasuffix1
- bra openfiles
-
- pcsuffix:
- lea text_pcsuf,a0
- moveq #3-1,d0
-
- pcsuffix1:
- move.b (a0)+,(a1)+
- dbf d0,pcsuffix1
- bra openfiles
-
- sf7suffix:
- lea text_sf7suf,a0
- moveq #4-1,d0
-
- sf7suffix1:
- move.b (a0)+,(a1)+
- dbf d0,sf7suffix1
-
- openfiles:
- clr.b (a1) ; end of filename
- move.l #sourcename,d1
- move.l #1005,d2
- move.l dosbase,a6
- jsr open(a6)
- tst.l d0
- beq err_nosource
- move.l d0,sourcehandle
-
- move.l #destname,d1
- move.l #1006,d2
- move.l dosbase,a6
- jsr open(a6)
- tst.l d0
- beq err_nodest
- move.l d0,desthandle
-
- readblock:
- move.l sourcehandle,d1
- move.l #sourcebuf,d2
- move.l #1024,d3
- move.l dosbase,a6
- jsr read(a6)
- add.l d0,readbytes
- move.l d0,d1
- beq closefiles ; readbytes=0 - quit
- subq.l #1,d1
- moveq #0,d2
-
- lea sourcebuf,a0
- lea destbuf,a1
-
- morecharacters:
- move.b (a0)+,d0
- bra cutspace
-
- checknormal:
- cmp.b #-2,mode
- beq tosf7
- cmp.b #-1,mode
- beq topc
- cmp.b #2,mode
- beq fromsf7
- cmp.b #3,mode
- beq toupcase
- cmp.b #4,mode
- beq tolowcase
-
- frompc:
- cmp.b #" ",d0
- bcs frompc1
- cmp.b #"~",d0
- bhi frompc1
- bra nextchar
-
- frompc1:
- cmp.b #$84,d0
- beq ami_lowae
- cmp.b #$94,d0
- beq ami_lowoe
- cmp.b #$8e,d0
- beq ami_upae
- cmp.b #$99,d0
- beq ami_upoe
- cmp.b #13,d0
- beq nochar
- cmp.b #0,d0
- beq nochar
- cmp.b #$1a,d0 ; ctrl+z
- beq nochar
- cmp.b #$c9,d0
- beq ami_bigcorner
- cmp.b #$bb,d0
- beq ami_bigcorner
- cmp.b #$c8,d0
- beq ami_bigcorner
- cmp.b #$bc,d0
- beq ami_bigcorner
- cmp.b #$cd,d0
- beq ami_doubleline
- cmp.b #$ba,d0
- beq ami_upline
- cmp.b #$b3,d0
- beq ami_upline
- cmp.b #$b0,d0
- beq ami_box
- cmp.b #$b1,d0
- beq ami_box
- cmp.b #$b2,d0
- beq ami_box
- cmp.b #$c4,d0
- beq ami_singleline
- cmp.b #$c0,d0
- beq ami_smallcorner
- cmp.b #$d9,d0
- beq ami_smallcorner
- cmp.b #$bf,d0
- beq ami_smallcorner
- cmp.b #$da,d0
- beq ami_smallcorner
- cmp.b #$d4,d0
- beq ami_bigcorner
- cmp.b #$c3,d0
- beq ami_smallcorner
- cmp.b #$b7,d0
- beq ami_smallcorner
- cmp.b #$b6,d0
- beq ami_bigcorner
- cmp.b #$d3,d0
- beq ami_smallcorner
- cmp.b #$d6,d0
- beq ami_smallcorner
- cmp.b #$bd,d0
- beq ami_smallcorner
- cmp.b #20,d0
- beq ami_182
- cmp.b #128,d0
- beq ami_231
-
- nextchar:
- move.b d0,(a1)+
- addq.l #1,d2
- add.w #1,col
-
- nochar:
- dbf d1,morecharacters
-
- move.l desthandle,d1
- move.l d2,d3
- add.l d2,writtenbytes
- move.l #destbuf,d2
- move.l dosbase,a6
- jsr write(a6)
-
- move.l #text_input,d2
- moveq #15,d3
- bsr printtext
-
- lea numberbuf,a0
- move.l readbytes,d0
- bsr num2ascii
-
- move.l a0,d2
- move.l d0,d3
- bsr printtext
-
- move.l #text_output,d2
- moveq #18,d3
- bsr printtext
-
- lea numberbuf,a0
- move.l writtenbytes,d0
- bsr num2ascii
-
- move.l a0,d2
- move.l d0,d3
- bsr printtext
-
- move.l #text_cr,d2
- moveq #1,d3
- bsr printtext
-
- bra readblock
-
- cutspace:
- move.l spacepointer,a2
- cmp.b #" ",d0
- beq addspace
- cmp.b #9,d0 ; tab
- beq addtab
-
- cmp.b #1,mode_cutspace
- bne cutspace2
-
- cmp.b #10,d0 ; lf
- beq cutspaces
- cmp.b #13,d0 ; cr
- beq cutspaces
-
- cutspace1:
- tst.l spacenumber
- bne linkspaces
- bra checknormal
-
- cutspace2:
- cmp.b #10,d0
- beq clearcol
- cmp.b #13,d0
- beq clearcol
- bra cutspace1
-
- clearcol:
- move.w #-1,col
- bra cutspace1
-
- addspace:
- addq.l #1,spacenumber
- move.b d0,(a2)+
- move.l a2,spacepointer
- add.w #1,col
- bra nochar
-
- addtab:
- move.b tabsize,d4
- bne tabconv
- bra addspace
-
- tabconv:
- ext.w d4
- ext.l d4
- move.w col,d3
- divu d4,d3
- swap d3
- sub.w d3,d4
- add.l d4,spacenumber
- add.w d4,col
- subq.w #1,d4
-
- tabconv1:
- move.b #" ",(a2)+
- dbf d4,tabconv1
- move.l a2,spacepointer
- bra nochar
-
- cutspaces:
- clr.l spacenumber
- move.l #spacebuf,spacepointer
- move.w #-1,col ; col will be zero when eol gets added
- bra checknormal
-
- linkspaces:
- move.l spacenumber,d3
- add.l d3,d2
- subq.l #1,d3
- lea spacebuf,a2
-
- linkspaces1:
- move.b (a2)+,(a1)+
- dbf d3,linkspaces1
- clr.l spacenumber
- move.l #spacebuf,spacepointer
- bra checknormal
-
- topc:
- cmp.b #"ä",d0
- beq pc_lowae
- cmp.b #"ö",d0
- beq pc_lowoe
- cmp.b #"Ä",d0
- beq pc_upae
- cmp.b #"Ö",d0
- beq pc_upoe
- cmp.b #13,d0
- beq nochar
- cmp.b #10,d0
- beq addcr
- cmp.b #0,d0
- beq nochar
- cmp.b #$1a,d0 ; ctrl+z
- beq nochar
- bra nextchar
-
- fromsf7:
- cmp.b #"{",d0
- beq ami_lowae
- cmp.b #"|",d0
- beq ami_lowoe
- cmp.b #"[",d0
- beq ami_upae
- cmp.b #"\",d0
- beq ami_upoe
- cmp.b #13,d0
- beq nochar
- cmp.b #0,d0
- beq nochar
- cmp.b #$1a,d0 ; ctrl+z
- beq nochar
- bra nextchar
-
- tosf7:
- cmp.b #"ä",d0
- beq sf7_lowae
- cmp.b #"ö",d0
- beq sf7_lowoe
- cmp.b #"Ä",d0
- beq sf7_upae
- cmp.b #"Ö",d0
- beq sf7_upoe
- cmp.b #10,d0
- beq addcr
- cmp.b #0,d0
- beq nochar
- cmp.b #$1a,d0 ; ctrl+z
- beq nochar
- bra nextchar
-
- toupcase:
- cmp.b #"ä",d0
- beq ami_upae
- cmp.b #"ö",d0
- beq ami_upoe
- cmp.b #"a",d0
- bcs nextchar
- cmp.b #"z",d0
- bhi nextchar
-
- eor.b #%100000,d0
- bra nextchar
-
- tolowcase:
- cmp.b #"Ä",d0
- beq ami_lowae
- cmp.b #"Ö",d0
- beq ami_lowoe
- cmp.b #"A",d0
- bcs nextchar
- cmp.b #"Z",d0
- bhi nextchar
-
- or.b #%100000,d0
- bra nextchar
-
- ami_182:
- move.b #182,d0
- bra nextchar
-
- ami_231:
- move.b #231,d0
- bra nextchar
-
- ami_singleline:
- move.b #"-",d0
- bra nextchar
-
- ami_box:
- move.b #$7f,d0
- bra nextchar
-
- ami_upline:
- move.b #"|",d0
- bra nextchar
-
- ami_doubleline:
- move.b #"=",d0
- bra nextchar
-
- ami_smallcorner:
- move.b #"+",d0
- bra nextchar
-
- ami_bigcorner:
- move.b #"#",d0
- bra nextchar
-
- ami_lowae:
- move.b #"ä",d0
- bra nextchar
-
- ami_lowoe:
- move.b #"ö",d0
- bra nextchar
-
- ami_upae:
- move.b #"Ä",d0
- bra nextchar
-
- ami_upoe:
- move.b #"Ö",d0
- bra nextchar
-
- pc_lowae:
- move.b #$84,d0
- bra nextchar
-
- pc_lowoe:
- move.b #$94,d0
- bra nextchar
-
- pc_upae:
- move.b #$8e,d0
- bra nextchar
-
- pc_upoe:
- move.b #$99,d0
- bra nextchar
-
- sf7_lowae:
- move.b #"{",d0
- bra nextchar
-
- sf7_lowoe:
- move.b #"|",d0
- bra nextchar
-
- sf7_upae:
- move.b #"[",d0
- bra nextchar
-
- sf7_upoe:
- move.b #"\",d0
- bra nextchar
-
- addcr:
- move.b #13,(a1)+
- addq.l #1,d2
- bra nextchar
-
- closefiles:
- move.l sourcehandle,d1
- move.l dosbase,a6
- jsr close(a6)
- move.l desthandle,d1
- move.l dosbase,a6
- jsr close(a6)
-
- move.l #text_final,d2
- moveq #26,d3
- bsr printtext
-
- move.l readbytes,d1
- move.l writtenbytes,d0
-
- sub.l d1,d0
- bmi closefiles1 ; negative
-
- move.l d0,d7
- beq closefiles2 ; if zero, no sign
-
- move.l #text_possign,d2
- moveq #1,d3
- bsr printtext
- bra closefiles2
-
- closefiles1:
- neg.l d0
- move.l d0,d7
-
- move.l #text_negsign,d2
- moveq #1,d3
- bsr printtext
-
- closefiles2:
- move.l d7,d0
- lea numberbuf,a0
- bsr num2ascii
-
- move.l a0,d2
- move.l d0,d3
- bsr printtext
-
- move.l #text_doublespace,d2
- moveq #2,d3
- bsr printtext
-
- move.l writtenbytes,d0
- move.l readbytes,d1
- bsr percentage
-
- lea numberbuf,a0
- bsr num2ascii
-
- move.l a0,d2
- move.l d0,d3
- bsr printtext
-
- move.l #text_percentsign,d2
- move.l #11,d3
- bsr printtext
-
- move.l #text_lf,d2
- move.l #1,d3
- bsr printtext
- bra endprogram1
-
- helptext:
- move.l #text_helptext,d2
- move.l #len_helptext,d3
- bsr printtext
- bra endprogram1
-
- credits:
- move.l #text_credits,d2
- move.l #len_credits,d3
- bsr printtext
- bra endprogram1
-
- if testmode=1
- err_testmode:
- move.l #$ffff,d0
-
- err_testmode1:
- move.w #$f00,$dff180
- dbf d0,err_testmode1
- bra endprogram1
- endc
-
- err_nosource:
- move.l #text_nosource,d2
- moveq #36,d3
- bsr printtext
- bra endprogram1
-
- err_nomemory:
- move.l #text_nomemory,d2
- moveq #26,d3
- bsr printtext
- bra endprogram1
-
- err_badcomline:
- move.l #text_badcomline,d2
- moveq #25,d3
- bsr printtext
- bra endprogram1
-
- err_nodest:
- move.l #text_nodest,d2
- moveq #41,d3
- bsr printtext
- bra endprogram2
-
- err_badmode:
- move.l #text_badmode,d2
- moveq #32,d3
- bsr printtext
- bra endprogram1
-
- err_nocomlinespace:
- move.l #text_nocomlinespace,d2
- moveq #60,d3
- bsr printtext
- bra endprogram1
-
- endprogram1:
- move.l #text_cursoron,d2
- moveq #5,d3
- bsr printtext
-
- move.l execbase,a6
- move.l dosbase,a1
- jsr closelibrary(a6)
- moveq #0,d0
- rts
-
- endprogram2:
- move.l sourcehandle,d1
- move.l dosbase,a6
- jsr close(a6)
- bra endprogram1
-
- **********
- ** SUBS **
- **********
-
- printtext:
- if testmode=1
- rts
- endc
- move.l outstruct,d1
- move.l dosbase,a6
- jsr write(a6)
- rts
-
- skipspace:
- cmp.b #" ",(a0)
- beq skipspace1
- rts
-
- skipspace1:
- add.l #1,a0
- cmp.l commandend,a0
- bcs skipspace
- move.l #0,a0
- rts
-
- findend:
- cmp.b #'"',(a0)
- beq findend_quote
-
- findend_space:
- addq.l #1,a0
- cmp.b #" ",(a0)
- beq findend_space1
- cmp.b #0,(a0)
- beq findend_space1
- cmp.l commandend,a0
- bls findend_space
- move.l #0,a0
- rts
-
- findend_space1:
- subq.l #1,a0
- rts
-
- findend_quote:
- addq.l #1,a0
- cmp.b #'"',(a0)
- bne findend_quote1
- rts
-
- findend_quote1:
- cmp.l commandend,a0
- bls findend_quote
- move.l #0,a0
- rts
-
- include "src:Num2ASCII-2.S"
- include "src:Percentage.S"
-
- **********
- ** DATA **
- **********
-
- section fastdata,data
-
- spacepointer:
- dc.l spacebuf
-
- text_helptext:
- incbin "src:Port/PortOpts1"
-
- text_credits:
- incbin "src:Port/PortOpts2"
-
- text_cursoroff:
- dc.b 27,"[0 p"
-
- text_cursoron:
- dc.b 27,"[1 p"
-
- text_badcomline:
- dc.b "ERROR! Bad commandline.",10
-
- text_nomemory:
- dc.b "ERROR! Not enough memory.",10
-
- text_badsource:
- dc.b "ERROR! Bad sourcefile.",10
-
- text_nosource:
- dc.b "ERROR! Could not open source file.",10
-
- text_nodest:
- dc.b "ERROR! Could not open destination file.",10
-
- text_badmode:
- dc.b "ERROR! Bad mode specification.",10
-
- text_nocomlinespace:
- dc.b "ERROR! The mode must be separated with at least one space.",10
-
- text_input:
- dc.b 27,"[1mInput: ",27,"[0m"
-
- text_output:
- dc.b " ",27,"[1mOutput: ",27,"[0m"
-
- dosname:
- dc.b "dos.library",0
-
- text_amigasuf:
- dc.b ".AMI"
-
- text_pcsuf:
- dc.b ".PC"
-
- text_sf7suf:
- dc.b ".SF7"
-
- text_cr:
- dc.b 13
-
- text_lf:
- dc.b 10
-
- text_final:
- dc.b 27,"[1mFile size change:",27,"[0m "
-
- text_negsign:
- dc.b "-"
-
- text_possign:
- dc.b "+"
-
- text_percentsign:
- dc.b "% "
-
- text_doublespace:
- dc.b " "
-
- mode_cutspace:
- dc.b 1
-
- if testmode=1
-
- test_comline:
- dc.b "-n -t8 l ram:test1",10
-
- test_comlineend:
-
- test_len = test_comlineend-test_comline
- endc
-
- section fastblank,bss
-
- writtenbytes:
- ds.l 1
-
- readbytes:
- ds.l 1
-
- sourcehandle:
- ds.l 1
-
- desthandle:
- ds.l 1
-
- outstruct:
- ds.l 1
-
- destnamestart:
- ds.l 1
-
- destnameend:
- ds.l 1
-
- destnamelen:
- ds.l 1
-
- sourcenamestart:
- ds.l 1
-
- sourcenameend:
- ds.l 1
-
- sourcenamelen:
- ds.l 1
-
- commandstart:
- ds.l 1
-
- commandend:
- ds.l 1
-
- commandlen:
- ds.l 1
-
- dosbase:
- ds.l 1
-
- spacenumber:
- ds.l 1
-
- col:
- ds.w 1
-
- mode:
- ds.b 1
-
- sourcename:
- ds.b 256
-
- destname:
- ds.b 256
-
- sourcebuf:
- ds.b 1024
-
- destbuf:
- ds.b 2048
-
- spacebuf:
- ds.b 1024
-
- numberbuf:
- ds.b 10
-
- tabsize:
- ds.b 1
-
- mode_case:
- ds.b 1
-
- len_helptext = text_credits-text_helptext
- len_credits = text_cursoroff-text_credits
-